package cjp.itcast.service.impl;

import cjp.itcast.pojo.vo.PortalVo;
import cjp.itcast.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cjp.itcast.pojo.Headline;
import cjp.itcast.service.HeadlineService;
import cjp.itcast.mapper.HeadlineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author HW
 * @description 针对表【news_headline】的数据库操作Service实现
 * @createDate 2024-11-14 12:19:05
 */
@Service
public class HeadlineServiceImpl extends ServiceImpl<HeadlineMapper, Headline>
        implements HeadlineService {
    @Autowired
    private HeadlineMapper headlineMapper;

    /**
     * 首页分页查询
     * 1.进行分页查询
     * 2.分页数据，拼接到result
     *
     *
     */
    @Override
    public Result findNewPage(PortalVo portalVo) {
        Page<Map> page = new Page<>();
        headlineMapper.selectMyPage(page, portalVo);

        List<Map> records = page.getRecords();
        Map data = new HashMap();
        data.put("pageData", records);
        data.put("pageNum", page.getCurrent());
        data.put("pageSize", page.getSize());
        data.put("pagePage", page.getPages());
        data.put("totalSize", page.getTotal());

        Map pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", data);
        // 响应JSON
        return Result.ok(pageInfo);
    }

}




